﻿@{
    Layout = null;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript" src="/Content/plupload_2_1_2/jquery.js" charset="UTF-8"></script>
    <script>
        //断点续传检测
        function checkUpload(up, file, chunkSize, offset) {
            var os = offset;
            if (file.name && chunkSize) {
                $.ajax({
                    type: "GET",
                    async: false,
                    url: "http://localhost:1334/home/IsContinue", //检查是否是断点续传
                    data: {
                        name: file.name,
                        fileSize: file.size,
                        lastModifiedDate: file.lastModifiedDate.getTime()
                    },
                    dataType: 'json',
                    success: function (data) {
                        os = Number(data.size);
                        $("#fid").val(data.fid);
                    }
                });
            }
            var url = up.settings.url;
            var strIndex = url.indexOf('?fId=');
            if (strIndex > -1) {
                url = url.substring(0, strIndex);
            }
            url = url + '?fId=' + $("#fid").val();
            var array = new Array(os, url);
            return array;
        }
    </script>
    <script src="/Content/plupload_2_1_2/moxie.min.js" type="text/javascript"></script>
    <script src="/Content/plupload_2_1_2/plupload.dev.js" type="text/javascript"></script>
    <!-- <script type="text/javascript" src="Content/Component/plupload_2_1_2/plupload.full.min.js" charset="UTF-8"></script>-->
    <script type="text/javascript" src="/Content/plupload_2_1_2/zh_CN.js" charset="UTF-8"></script>
</head>
<body>
    <div id="filelist">
    </div>
    <br />
    <a id="pickfiles" href="javascript:;">选择文件</a> <a id="uploadfiles" href="javascript:;">
        上传文件
    </a> <a id="stop" href="javascript:;">暂停</a> <a id="A1" href="javascript:;">启动</a>
    <div id="console">
    </div>
    <script type="text/javascript">

        // 初始化
        $(function () {
            var uploader = new plupload.Uploader({
                runtimes: 'html5,flash,silverlight,html4', // 这里是说用什么技术引擎
                url: 'http://localhost:1334/home/Upload', // 服务端上传路径
                max_file_size: '6097mb', // 文件上传最大限制。
                max_file_count: 20, //指示用户可以同时上传文件的最大数量
                chunk_size: 1024*1024*10, // 上传分块每块的大小，这个值小于服务器最大上传限制的值即可,0表示不启用分块。
                browse_button: 'pickfiles',
                // plupload.flash.swf 的所在路径
                flash_swf_url: '/Content/plupload_2_1_2/Moxie.swf',
                // silverlight所在路径
                silverlight_xap_url: '/Content/plupload_2_1_2/Moxie.xap',
                //  这个数组是选择器，就是上传文件时限制的上传文件类型
                //filters: [{
                //    title: "Image files",
                //    extensions: "jpg,gif,png"
                //}, {
                //    title: "Zip files",
                //    extensions: "zip,avi,rar"
                //}],
                //附加参数
                multipart_params: {
                    app: 'epm',
                    //crop: true,
                    //isbim: true,
                },
                rename: false, // 是否重命名文件
                sortable: true, // Sort files
                dragdrop: true, //启用文件到小部件能够拖放(操作)(目前唯一HTML5支持)
                // Views to activate
                views: {
                    list: true,
                    thumbs: true, // Show thumbs
                    active: 'thumbs'
                },
                init: {
                    PostInit: function () {
                        $('#filelist').html("");

                        $('#uploadfiles').click(function () {
                            uploader.start();
                            return false;
                        });
                        $('#stop').click(function () {
                            uploader.stop();
                            return false;
                        });
                    },
                    FilesAdded: function (up, files) {
                        $('#filelist').html("");
                        plupload.each(files, function (file) {
                            //var typeList = ["doc", "docx", "xls", "xlsx", "pdf", "rar", "zip", "7z", "jpg"];
                            //var fileType = File(typeList, file);
                            //if (!fileType) {
                            //    files.pop();
                            //    parent.layer.alert('上传文件类型仅支持doc、xls、pdf、压缩文件、图片格式，请重新上传', { icon: 2 });
                            //}
                            $('#filelist').append('<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div>');
                        });
                    },
                    UploadProgress: function (up, file) {
                        //alert(JSON.stringify(file));
                        $("#" + file.id + " b:eq(0)").html('(<span>' + file.percent + "%</span>)");
                    },
                    //BeforeUpload: function (up, file) {
                    //},
                    FileUploaded: function (uploader, file, responseObject) {
                        alert(responseObject.response);
                        console.log(responseObject.response);
                    },
                    Error: function (up, err) {
                        $('#console').append("\nError #" + err.code + ": " + err.message);
                    }
                }
            });
            uploader.init();

        });
    </script>
    <input type="hidden" id="fid" />
</body>
</html>
